import {
  UPDATE_LOADING,
  UPDATE_DIRECTION,
  DDCONFIG_SUCCESS,
  DDCONFIG_ERROR,
  UPDATE_CODE,
  LOGIN_SUCCESS,
  LOGIN_ERROR,
  UPDATE_SYS_LEVEL,
  INCREMENT,
  DECREMENT,
  HIDE_COVER,
  SHOW_COVER,
  UPDATE_TOKEN,
  UPDATE_USER,
  UPDATE_TARGET,
  UPDATE_CLIENT_DETAIL,
  HIDE_DIALOG,
  SHOW_DIALOG,
  UPDATE_DIALOG_MESSAGE
} from '../mutation-types';

import actions from '../actions'


const state = {
  count: 0,
  isLoading: false, //路由加载标志位
  direction: 'forward', //路由动画变量
  ddConfig: null,
  ddConfigStatus: null,
  code: 333,
  user: {
  // "id": 1,
  // "uid": 2,
  // "username": "Evan",
  // "mobile": "18620300370",
  // "reg_time": "2017-03-22 11:34:28",
  // "insert_time": "2017-03-22 11:34:28",
  // "headimgurl": "http://static.dingtalk.com/media/lADOAIBV2TAw_48_48.jpg",
  // "ding_uid": "007",
  // "teams": [
  //   {
  //   "team_id": 3
  //   }
  // ],
  // "is_team_manager": 1
  },
  imgServer: 'http://120.24.48.9:9010/img/',
  isShowCover: false,
  token : '',
  target : null,
  dialogShow: false,
  dialogMessage: '',
  clientsDetail:{},
  filterOptions:[
    {
      title: '搜索',
      class: 'txt-center',
      showArrow: true,
      name: 'search'
    },
    {
      title:'筛选',
      class:'txt-center',
      value: '1',
      checked: '1',
      name: 'filter',

      options:[
        // 未联系时间开始
        {
          text : '未联系时间',
          value : '1',
          checked: '2',
          name:'connet_time',
          options: [
            {
              text : '一周到两周',
              value : '1'
            },
            {
              text : '两周到一月',
              value : '2'
            },
            {
              text : '一月到两月',
              value : '3'
            },
            {
              text : '两月以上',
              value : '4'
            }
          ]
        },
        // 未联系时间结束

        // 负责人开始
        {
          text : '负责人',
          value : '2',
          checked: '1',
          name:'suid',
          options: [
            {
              text : '营销顾问1',
              value : '1'
            },
            {
              text : '营销顾问2',
              value : '2'
            },
            {
              text : '营销顾问3',
              value : '3'
            }
          ]
        },
        // 负责人结束

        // 所属团队开始
        {
          text : '所属团队',
          value : '3',
          checked: '1',
          name: 'teamId',
          options: [
            {
              text : '全优加',
              value : '1'
            },
            {
              text : '团队1',
              value : '2'
            },
            {
              text : '团队2',
              value : '3'
            }
          ]
        },
        // 所属团队开始

        // 客户属性开始
        {
          text : '客户属性',
          value : '4',
          checked: '1',
          name: 'custom_property',
          options: [
            {
              text : '一般客户',
              value : '0'
            },
            {
              text : '意向客户',
              value : '1'
            },
            {
              text : '成交客户',
              value : '2'
            },

            {
              text : '无效客户',
              value : '3'
            },

            {
              text : '其他客户',
              value : '4'
            },

          ]
        },
        // 客户属性结束

        // 跟进状态开始
        {
          text : '跟进状态',
          value : '5',
          checked: '1',
          name:'custom_status',
          options: [
            {
              text : '初步接洽',
              value : '1'
            },
            {
              text : '需求确定',
              value : '2'
            },
            {
              text : '方案/报价',
              value : '3'
            },

            {
              text : '谈判/合同',
              value : '4'
            },

            {
              text : '成交',
              value : '5'
            },

          ]
        }
        //跟进状态结束
      ],
    },

    {
      title : '排序',
      class: 'txt-center',
      checked: '1',
      name:'order_by',
      options: [
        {
        text : '跟进时间倒序',
        value: '1'
        },

        {
        text : '更新时间倒序',
        value: '2'
        },

        {
        text : '姓名正序',
        value: '3'
        },

      ]
    }
  ],
  customStatusOptions:[
    {
      key: 'INT',
      value: '初步接洽'
    },
    {
      key: 'XQ#',
      value: '需求确定'
    },
    {
      key: 'FA#',
      value: '已成交客户'
    },
    {
      key: 'TP#',
      value: '无效客户'
    },
    {
      key: 'CJ#',
      value: '其它客户'
    }
  ],

  customPropertyOptions:[
    {
      key: 'YX#',
      value: "意向客户"
    },

    {
      key : 'YB#',
      value : '一般客户'
    },

    {
      key: 'YCJ',
      value: '已成交客户'
    },

    {
      key: 'WX#',
      value: '未知来源'
    },

    {
      key: 'QT#',
      value: '其它'
    }
  ]

}

const mutations = {
  [INCREMENT] (state) {
    state.count++
  },
  [DECREMENT] (state) {
    state.count--
  },
  [UPDATE_LOADING] (state, status) {
    state.isLoading = status
  },
  [UPDATE_DIRECTION] (state, direction) {
    state.direction = direction
  },
  [DDCONFIG_SUCCESS] (state, config) {
    state.ddConfig = config;
    state.ddConfigStatus = true;
    console.debug(JSON.stringify(config), 'warnnnnnn')
  },
  [DDCONFIG_ERROR] (state, config) {
    state.ddConfig = null;
    state.ddConfigStatus = false;
  },

  [UPDATE_CODE] (state, code) {
    state.code = code
  },

  [UPDATE_TOKEN] (state, token) {
    console.debug('update token', token)
    state.token = token
  },

  [LOGIN_SUCCESS] (state, user) {
    state.user = user
  },

  [UPDATE_USER] (state, user) {
    console.log('UPDATE_USER', JSON.stringify(user))
    state.user = user
  },

  [LOGIN_ERROR] (state, user) {
    state.user = false
  },

  [HIDE_COVER] (state) {
    state.isShowCover = false;
  },

  [SHOW_COVER] (state) {
    state.isShowCover = true;
  },

  [UPDATE_TARGET] (state, target) {
  state.target = target
  },

  [UPDATE_CLIENT_DETAIL](state, clientsDetail) {
    state.clientsDetail = clientsDetail;
  },

  [UPDATE_DIALOG_MESSAGE](state, message) {
    state.dialogMessage = message;
  },

  [SHOW_DIALOG](state) {console.log(state)
    state.dialogShow = true;
  },

  [HIDE_DIALOG](state) {console.log(state)
    state.dialogShow = false;
  },

  INCREMENT(state) {
    console.log('test INCREMENT')
    state.count++
  },

  DECREMENT(state) {
    state.count--
  }

}


export default {
  state,
  mutations,
  actions
}
